Reliability and Spare Parts Prediction
logo



Calculation of quantities of spare parts and the estimation of availability.

### IMPORTING R SCRIPTS
rm(list = ls())
# setwd(paste0(rprojroot::find_rstudio_root_file(), "/analysis"))
library(klaR)
source("../code/setup.R")
library(gower)
library(cluster)
knitr::opts_chunk$set(comment = "", collapse = FALSE)
options(max.print="100")
source("../code/var_dict.R", encoding = "UTF-8")
## Warning: `as_tibble.matrix()` requires a matrix with column names or a `.name_repair` argument. Using compatibility `.name_repair`.
## This warning is displayed once per session.
source("../code/functions.R")
source("../code/utils.R", encoding = "UTF-8")
## Warning: funs() is soft deprecated as of dplyr 0.8.0
## Please use a list of either functions or lambdas: 
## 
##   # Simple named list: 
##   list(mean = mean, median = median)
## 
##   # Auto named with `tibble::lst()`: 
##   tibble::lst(mean, median)
## 
##   # Using lambdas
##   list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## This warning is displayed once per session.
source("../code/setup.R")
# source_python("../code/setup.py")
# source_python("../code/GBClassifier.py")
# source_python("../code/utils.py")
spart %>% 
  mutate_at(c("q_spart", "section", 
              "centre_ID", "equip_sap"), as.integer) %>% 
  mutate(cost_part = round(as.numeric(cost_part), 2)) %>% 
  mutate_at(c("post_date", "change_date", "date"), as_date)
  # mutate(date = as)


features <- c()
mc2 <- spart %>% 
  select(c(bwart, spart_id, q_spart))
set.seed(100000)

cluster.results <-kmodes(mc2, modes=6, weighted = FALSE)

# print(cluster.results)

k.max <- 10

wss <- sapply(4:k.max, 
              function(k){set.seed(100000)
                sum(kmodes(mc2, modes=k, weighted = FALSE)$withindiff)})

wss
[1] 1166572 1163516 1162740 1162738 1084858 1084857 1081115
plot(4:k.max, wss,
     type="b", pch = 19, frame = FALSE, 
     xlab="Number of clusters K",
     ylab="Total within-clusters sum of squares")

# 2015-06-10 00:00:00.000

# 2015 06 30 07 00 00

1 Data Wrangling


1.1 Load Data

BWART corresponds to the warehouse movement. If a replacement is taken out of the warehouse the quantity is negative and it is labelled as Z21. If the replacement is returned to the warehouse the quantity is positive and it is labelled as Z22.

spart %>% 
  group_by(spart_id) %>% 
  summarise(freq = round(n()/100, 0)) %>% 
  arrange(-freq, .by_group = TRUE) %>%
  ungroup() %>%
  top_n(10) %>% 
  ggplot(aes(reorder(spart_id, freq), y = freq, fill = freq)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(x = "Failed Components",
       y = "Frequency",
       title = "Top Failure Modes") +
  theme(legend.position = "none", 
        axis.title.y = element_text(size = 10), 
        axis.text.y = element_text(size = 10), 
        axis.title.x = element_text(size = 15),
        axis.text.x = element_text(size = 15), 
        plot.title = element_text(size = 25, hjust = 0.2)) +
  scale_fill_gradientn(name = "", 
                       colours = rev(brewer.pal(10, "Spectral"))) +
  geom_text(aes(label = freq), hjust = 0.5, size = 8.5) +
  coord_flip()
Selecting by freq

# parts$BWART

Almost al Bwart are either Z21 or Z22.

spart
spart %>% 
  group_by(bwart) %>% 
  summarise(freq = round(n()/100, 0)) %>% 
  ungroup() %>% 
  ggplot(aes(reorder(bwart, freq), y = freq, fill = freq)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(x = "Failed Components",
       y = "Frequency",
       title = "Top Failure Modes") +
  theme(legend.position = "none", 
        axis.title.y = element_text(size = 10), 
        axis.text.y = element_text(size = 10), 
        axis.title.x = element_text(size = 15),
        axis.text.x = element_text(size = 15), 
        plot.title = element_text(size = 25, hjust = 0.2)) +
  scale_fill_gradientn(name = "", 
                       colours = rev(brewer.pal(10, "Spectral"))) +
  geom_text(aes(label = freq), hjust = 0.5, size = 8.5) +
  coord_flip()

# parts$BWART
 




A work by Cecil V.